#include "Depot.hpp"


std::string     Depot::toString() const
{
    std::string res;
    char        buffer[0x1000];
    
    sprintf(buffer, "DEPOT - %f - %f DUE : %f", veX, veY, deDueDate);
    res = buffer;
    return (res);
}

void	Depot::addTournee(unsigned inTournee, Vertex& inPred, Vertex& inSucc)
{
	std::pair<Vertex*, Vertex*>		depot_sp(&inPred, &inSucc);
	deSuccsPredsByTournee[inTournee] = depot_sp;
}

void	Depot::removeTournee(unsigned inTournee) EXC_THROWER()
{
	std::map<unsigned, std::pair<Vertex*, Vertex*> >::iterator it;
	
	if ((it = deSuccsPredsByTournee.find(inTournee)) == deSuccsPredsByTournee.end())
		EXC_THROW("trying to remove tournee which does not exist");
	deSuccsPredsByTournee.erase(it);
}

void	Depot::setPredForTournee(unsigned inTournee, Vertex&	inVertex) EXC_THROWER()
{
	std::map<unsigned, std::pair<Vertex*, Vertex*> >::iterator it;
	
	if ((it = deSuccsPredsByTournee.find(inTournee)) == deSuccsPredsByTournee.end())
		EXC_THROW("trying to remove tournee which does not exist");
	
	dePreds[inTournee] = &inVertex;
}

void	Depot::setSuccForTournee(unsigned inTournee, Vertex&	inVertex) EXC_THROWER()
{
	if (inTournee > dePreds.size())
		EXC_THROW("inTournee given does not exist");
		
	deSuccs[inTournee] = &inVertex;
}

std::pair<Vertex*, Vertex*>&		Depot::getSuccPred(unsigned inTournee) EXC_THROWER()
{
	std::map<unsigned, std::pair<Vertex*, Vertex*> >::iterator it;
	
	if ((it = deSuccsPredsByTournee.find(inTournee)) == deSuccsPredsByTournee.end())
		EXC_THROW("trying to access tournee which does not exist");
		
	return (it->second);
}


